package util

import "fmt"

type ListNode struct {
	Val  int
	Next *ListNode
}

func GenerateLinkedList(data []int) *ListNode {
	var head *ListNode = nil

	for _, v := range data {
		if head == nil {
			head = &ListNode{Val: v, Next: nil}
		} else {
			var last *ListNode = head
			for last.Next != nil {
				last = last.Next
			}
			last.Next = &ListNode{Val: v, Next: nil}
		}
	}
	return head
}

func PrintLinkedList(head *ListNode) {
	for head != nil {
		fmt.Printf("%d ", head.Val)
		head = head.Next
	}
}
